home *** CD-ROM | disk | FTP | other *** search
- #!/bin/csh -f
- # wrap -- word WRAP a. el-khadra & p. griffin 7/25/91
- #
- # usage: wrap [ -w nn ] oldfile , nn=width (default=80)
- #
- # Notes -- 1. for wrapped lines , spaces are contracted to one, or two if
- # following ~[.!?]
- # 2. old file replace by wrapped file
- #
- set width = 80
- if ($#argv > 0) then
- if ( "$argv[1]" == '-w') then
- shift
- set a = $argv[1]
- if ($a !~ [0-9]* || $a == 0 || $a >999) then
- echo ww\: Bad width argument $a
- exit 1
- else
- set width = $a
- shift
- endif
- endif
- if ($#argv > 1) then
- echo usage': wrap[ -w nn] oldfile' , where nn=width '(default=80)'
- exit 1
- endif
- if (! -opr $argv[1] ) then
- echo ww\: No file $argv[1]
- exit
- endif
- set tf = /tmp/ww:t.$$
- awk "{lt= $width"' \
- if ( length($0) > lt) { \
- line = "" ; ll= 0 \
- for (i=1; i<= NF; i++) { \
- if ( $i ~ /[.\!?]$/ ) { {newpart= $i " "} ;lp= length($i)+2} \
- else {{newpart=$i " "} ; lp= length($i) +1 } \
- if ( ll + length($i) > lt) { \
- if ( ll =0 ) {print $i} \
- else { {print line } ; {line= newpart} ; ll=lp }} \
- else {{newline = line newpart} ; ll += lp ; {line= newline}}} \
- if (ll > 0) {print line} } \
- else {print} }' $argv[1] > $tf
- mv $tf $argv[1]
-
-